<%@ page import="com.cxl.entity.User" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--
  Created by IntelliJ IDEA.
  User: 20971
  Date: 2021/12/30
  Time: 11:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>教育平台系统</title>
    <link rel="stylesheet" href="resource/css/bootstrap.css">
    <script type="text/javascript" src="resource/js/jquery-3.2.1.js"></script>
</head>
<body>
<%
    User user = (User) request.getSession().getAttribute("LONGUSER");
%>
<h1 class="text-center">
    欢迎<%=user.getUsername()%>
         <c:if test="<%=user.getRole()==0%>">学生</c:if>
        <c:if test="<%=user.getRole()==1%>">讲师</c:if>
        <c:if test="<%=user.getRole()==2%>">管理员</c:if>
    登陆到教育平台系统
</h1>

<form action="list" method="post">

    <c:if test="<%=user.getRole()==1%>">
        <input type="button" value="发布课程" onclick="toadd(<%=user.getUid()%>)">
    </c:if>

    <c:if test="<%=user.getRole()==2%>">
        课程名称:<input type="text" name="cname" value="${vo.cname}">
        发布开始日期:
            <input type="date" name="indate" value='<fmt:formatDate value="${vo.indate}" pattern="yyyy-MM-dd"></fmt:formatDate>'>
        至
            <input type="date" name="outdate" value='<fmt:formatDate value="${vo.outdate}" pattern="yyyy-MM-dd"></fmt:formatDate>'>
        <button>搜索</button>
    </c:if>
    <table class="table table-hover">
        <tr>
            <td>序号</td>
            <td>课程名称</td>
            <td>课程图标</td>
            <td>课程分类</td>
            <td>课程发布日期</td>
            <td>课程发布者</td>
            <td>学习人数
                <input type="hidden" name="mysort" value="${vo.mysort}" id="mysort">
                <c:if test="${vo.mysort==null || vo.mysort=='desc'}">
                    <a href="javascript:tosort('asc')">升序</a>
                </c:if>
                <c:if test="${vo.mysort=='asc'}">
                    <a href="javascript:tosort('desc')">降序</a>
                </c:if>
            </td>
            <c:if test="<%=user.getRole()!=0%>">
                <td>课程状态</td>
                <td>审核状态</td>
                <td>操作</td>
            </c:if>
            <c:if test="<%=user.getRole()==0%>">
                <td>学习状态</td>
            </c:if>
        </tr>
        <c:forEach var="c" items="${pg.list}" varStatus="i">
            <tr>
                <td>${i.count}</td>
                <td>
                    <c:if test="<%=user.getRole()==0%>">
                        <a href="javascript:todetails(${c.cid})">${c.cname}</a>
                    </c:if>
                    <c:if test="<%=user.getRole()!=0%>">
                        ${c.cname}
                    </c:if>
                </td>
                <td><img src="${c.pic}" width="120" height="100"></td>
                <td>${c.tname}</td>
                <td><fmt:formatDate value="${c.putdate}" pattern="yyyy-MM-dd"></fmt:formatDate></td>
                <td>${c.uname}</td>
                <td>${c.number}人</td>
                <c:if test="<%=user.getRole()==0%>">
                    <td>
                        <a href="#">${c.apply==0?'报名学习':'正在学习中'}</a>
                    </td>
                </c:if>

                <c:if test="<%=user.getRole()!=0%>">
                    <td>
                        <c:if test="${c.state==0}">
                             <a href="javascript:tostate(${c.cid}+'',1)">下架</a>
                        </c:if>
                        <c:if test="${c.state==1}">
                             <a href="javascript:tostate(${c.cid}+'',0)">上架</a>
                        </c:if>
                    </td>
                    <td>${c.check==0?'未审核':c.check==1?'未通过':'已通过'}</td>
                    <td>
                        <c:if test="<%=user.getRole()==1%>">
                            <input type="button" value="上传课程简介视频" onclick="tovideo(${c.cid})">
                        </c:if>

                        <c:if test="<%=user.getRole()==2%>">
                            <a href="javascript:topass(${c.cid}+'',2)">通过</a>
                            <a href="javascript:topass(${c.cid}+'',1)">驳回</a>
                            <a href="javascript:topdf(${c.cid})">导出PDF</a>
                        </c:if>
                    </td>
                </c:if>
            </tr>
        </c:forEach>
        <tr>
            <td colspan="10">
                <input type="hidden" name="pageNum" value="${pg.pageNum}" id="page">
                <input type="button" value="首页" onclick="topage(1)">
                <c:forEach var="g" items="${pg.navigatepageNums}">
                    <input type="button" value="${g}" onclick="topage(${g})">
                </c:forEach>
                <input type="button" value="下一页" onclick="topage(${pg.nextPage==0?pg.pages:pg.nextPage})">
            </td>
        </tr>
    </table>
</form>

<script>
    /*详情*/
    function todetails(val) {
        location.href="getdetails?cid="+val;
    }
    /*上传课程简介视频*/
    function tovideo(cid) {
        location.href="getVideo?cid="+cid;
    }
    /*发布课程*/
    function toadd(uid) {
        location.href = "toadd?uid="+uid;
    }
    /*上架下架*/
    function tostate(cid,val) {
        location.href = "getState?state="+val+"&cid="+cid;
    }
    /*分页条件一致性*/
    function topage(pageNum) {
        $("#page").val(pageNum);
        location.href = "list?role=<%=user.getRole()%>"+"&"+$("form").serialize();
    }
    /*排序*/
    function tosort(val) {
        $("#mysort").val(val);
        $("form").submit();
    }

    /*通过 + 驳回*/
    function topass(cid,val) {
        location.href = "getpass?check="+val+"&cid="+cid;
    }

    /*导出PDF*/
    function topdf(val) {
        location.href = "getpdf?cid="+val;
    }
</script>
</body>
</html>
